/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.BusinessLogicLayer;

import edu.nii.qlks.DataAccessLayer.MSSQLConnectUnit;
import edu.nii.qlks.DataTransferObject.LoaiTaiKhoanInfo;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;

/**
 *
 * @author MARS_NHO
 */
public class LoaiTaiKhoanBLL {
    MSSQLConnectUnit _connect;
    ResultSet  _result;
 
    
    public Vector LayDS(String Condition, String OderBy) throws Exception{
        Vector vt = new Vector();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("LOAITAIKHOAN", Condition, OderBy);
        
        while (_result.next()){
            Vector vt_row = new Vector();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public Vector LayDS(String Condition) throws Exception{
         return LayDS(Condition, null);
    }
    
    public Vector LayDS() throws Exception{
        return LayDS(null);
    }
    
    public void Insert(LoaiTaiKhoanInfo loaiTaiKhoanInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("MaLoaiTaiKhoan", loaiTaiKhoanInfo.getMaLoaiTaiKhoan());
        map.put("TenLoaiTaiKhoan", loaiTaiKhoanInfo.getTenLoaiTaiKhoan());
        _connect.Insert("LOAITAIKHOAN", map);
    }
    
     
    public void Inserts(HashSet<LoaiTaiKhoanInfo> loaiTaiKhoanInfos) throws Exception{
        for (LoaiTaiKhoanInfo loaiTaiKhoanInfo:loaiTaiKhoanInfos) {
            this.Insert(loaiTaiKhoanInfo);
        }
    }
    
    public void Update(LoaiTaiKhoanInfo loaiTaiKhoanInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("TenLoaiTaiKhoan", loaiTaiKhoanInfo.getTenLoaiTaiKhoan());
        _connect.Update("LOAITAIKHOAN", map, "MaLoaiTaiKhoan = " + loaiTaiKhoanInfo.getMaLoaiTaiKhoan());
    }
    
    public void Updates(HashSet<LoaiTaiKhoanInfo> loaiTaiKhoanInfos) throws Exception{
        for (LoaiTaiKhoanInfo loaiTaiKhoanInfo:loaiTaiKhoanInfos){
            this.Update(loaiTaiKhoanInfo);
        }
    }
    
    public void Delete(LoaiTaiKhoanInfo loaiTaiKhoanInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _connect.Delete("LOAITAIKHOAN", "MaLoaiTaiKhoan = " + loaiTaiKhoanInfo.getMaLoaiTaiKhoan());
    }
    
    public void Deletes(HashSet<LoaiTaiKhoanInfo> loaiTaiKhoanInfos) throws Exception{
         for (LoaiTaiKhoanInfo loaiTaiKhoanInfo:loaiTaiKhoanInfos){
            this.Delete(loaiTaiKhoanInfo);
        }
    }
    
    public String TaoMaTuDong(String maGoc, int batDau){
        String ma = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.TaoMaTuDong(maGoc, batDau);
        return ma;
    }
    
    public Vector LayDS_TenLoaiTaiKhoan(String TenLoaiTaiKhoan) throws Exception{
        Vector vt = new Vector();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("LOAITAIKHOAN", "TenLoaiTaiKhoan = '" + TenLoaiTaiKhoan + "'", null);
        
        while (_result.next()){
            Vector vt_row = new Vector();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
}
